package top.aiprogram.login.dao;

import top.aiprogram.common.utils.DBUtils;
import top.aiprogram.login.Teacher;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class TeacherDao {
    public Teacher queryTeacher(String username,String password) throws Exception{

        Connection conn =  DBUtils.getConn();
        String sql = "SELECT Tid,Tname,username,password FROM teacher WHERE username='"+username+"' AND password= '"+password+"'";
        PreparedStatement pstm =  conn.prepareStatement(sql);
        ResultSet resultSet =  pstm.executeQuery();
        Teacher teacher = null;
        while(resultSet.next()){
            teacher =  new Teacher();
            teacher.setTid(resultSet.getInt("Tid"));
            teacher.setTname(resultSet.getString("Tname"));
            teacher.setUsername(resultSet.getString("username"));
        }
        return teacher;
    }
}
